package com.ruanyun.sys.modular.system.mapper;

import com.ruanyun.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.datascope.DataScope;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruanyun.sys.modular.system.model.result.CountyResult;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员表 Mapper 接口
 * </p>
 *
 * @author administrator
 * @since 2018-12-07
 */
@Repository
public interface UserMapper extends BaseMapper<User> {

    /**
     * 修改用户状态
     */
    int setStatus(@Param("userId") Long userId, @Param("status") String status);

    /**
     * 修改密码
     */
    int changePwd(@Param("userId") Long userId, @Param("pwd") String pwd);

    /**
     * 根据条件查询用户列表
     */
    Page<Map<String, Object>> selectUsers(@Param("page") Page page, @Param("dataScope") DataScope dataScope, @Param("name") String name, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("deptId") Long deptId,@Param("pid") String pid);

    /**
     * 设置用户的角色
     */
    int setRoles(@Param("userId") Long userId, @Param("roleIds") String roleIds);

    /**
     * 通过账号获取用户
     */
    User getByAccount(@Param("account") String account);


    /*获取当前后台登录用户的统一社会信用代码*/
    @Select(" SELECT social_credit_code as socialCode from t_user WHERE phone =  #{account}")
    String getSocialCode(@Param("account") String account);

    /*获取当前登录企业id*/
    @Select(" SELECT id as cid from t_basicinfo WHERE social_credit_code = #{socialCode}")
    Integer getCid(@Param("socialCode") String socialCode);

    /*获取县级信息*/
    @Select(" SELECT name as text,user_id as value FROM sys_user WHERE role_id = '1402427690353750018'")
    List<CountyResult> getCountyList();

    /*获取当前登录所属县级*/
    @Select("SELECT pid  from t_user WHERE phone =  #{account}")
    String getCountyId(@Param("account") String account);
}
